home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / m_to_r / roppop / ropwin.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  4.7 KB  |  193 lines

  1. unit Ropwin;
  2.  
  3. { This is the window class don't install it. install Troppop.pas
  4.  TRopPop 1.0  (c) 1995 by Eyal Frank
  5.   Tel Aviv
  6.   Israel
  7.   CIS : 100274,3376
  8.   EMail frank-e@Trendline.co.il
  9.  
  10.   This is my first component , i realy want to get any feedback,
  11.   So drop me an Email please.
  12. }
  13.  
  14. interface
  15.  
  16. uses
  17.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  18.   Forms, Dialogs, ExtCtrls;
  19.  
  20. type
  21.   TRopInst = class(TForm)
  22.     Timer1: TTimer;
  23.     procedure FormPaint(Sender: TObject);
  24.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  25.       Shift: TShiftState);
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  28.     procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  29.       Shift: TShiftState; X, Y: Integer);
  30.     procedure Timer1Timer(Sender: TObject);
  31.   private
  32.     procedure WMEraseBkng(var MSg:TWMEraseBkgnd);message WM_ERASEBKGND;
  33.   protected
  34.     procedure CreateParams(var Params: TCreateParams);override;
  35.   public
  36.     sText:TStringList;
  37.     formBrush:TBrush;
  38.     xPos,yPos:Integer;
  39.     timerClose:Integer;
  40.     procedure DoInit;
  41.  
  42.   end;
  43.  
  44. const
  45.   SD_WIDTH = 16;
  46.   SD_HEIGHT = 16;
  47.   SD_OFFSET = 16;
  48. var
  49.   RopInst: TRopInst;
  50.  
  51. implementation
  52.  
  53. {$R *.DFM}
  54.  
  55. procedure TRopInst.CreateParams(var Params: TCreateParams);
  56. begin
  57.     inherited CreateParams(Params);    { call the inherited first }
  58.     with Params do
  59.     begin
  60.       Style := Style or WS_POPUP;
  61.       Style := Style and not (WS_CAPTION or WS_CHILD);
  62.       WindowClass.hbrBackground:=GetStockObject(NULL_BRUSH);
  63.       WindowClass.Style:= WindowClass.Style or CS_SAVEBITS;
  64.     end;
  65. end;
  66. procedure TRopInst.WMEraseBkng(var MSg:TWMEraseBkgnd);
  67. begin
  68.      Msg.Result:=1;
  69. end;
  70. procedure TRopInst.FormPaint(Sender: TObject);
  71. const
  72. bmBits: Array[0..7] of Integer=($AA,$55,$AA,$55,$AA,$55,$AA,$55);
  73. var
  74. rect,rc:TRect;
  75. szText:PChar;
  76. bm:HBITMAP;
  77. hbr,hold:HBRUSH;
  78. begin
  79.    {if csDesigning in ComponentState then
  80.      exit;}
  81.    bm:=CreateBitmap(8, 8, 1, 1, @bmBits[0]);
  82.    szText:=sText.GetText;
  83.    Canvas.Rectangle(1 ,
  84.                    1,
  85.                    ClientWidth - SD_WIDTH,
  86.                    ClientHeight - SD_HEIGHT);
  87.    Canvas.Brush:=formBrush;
  88.    Canvas.Rectangle(1 ,
  89.                    1,
  90.                    ClientWidth - SD_WIDTH,
  91.                    ClientHeight - SD_HEIGHT);
  92.     SetBkMode(Canvas.Handle,TRANSPARENT);
  93.  
  94.     rc:=ClientRect;
  95.     {// Write some text to this window}
  96.     rect.left   := rc.left + 1 + 5;
  97.     rect.top    := rc.top + 1 + 5;
  98.     rect.right  := rc.right - SD_WIDTH - 5;
  99.     rect.bottom := rc.bottom - SD_HEIGHT - 5;
  100.     DrawText(Canvas.Handle, szText, -1, rect, DT_LEFT);
  101.  
  102.     hbr := CreatePatternBrush(bm);
  103.     hOld := SelectObject(Canvas.Handle, hbr);
  104.     PatBlt(Canvas.Handle,
  105.            rc.left + SD_OFFSET,
  106.            rc.bottom - SD_HEIGHT,
  107.            rc.right - SD_OFFSET,
  108.            SD_HEIGHT,
  109.            $A000C9);
  110.  
  111.      { right-side shadow}
  112.  
  113.     PatBlt(Canvas.Handle,
  114.            rc.right - SD_WIDTH,
  115.            rc.top + SD_OFFSET,
  116.            SD_WIDTH,
  117.            rc.bottom,
  118.            $A000C9);
  119.     SelectObject(Canvas.Handle, hOld);
  120.     DeleteObject(hbr);
  121.     DeleteObject(bm);
  122.  
  123. end;
  124.  
  125. procedure TRopInst.FormKeyDown(Sender: TObject; var Key: Word;
  126.   Shift: TShiftState);
  127. begin
  128.    Close;
  129. end;
  130.  
  131. procedure TRopInst.DoInit;
  132. var
  133. cx,cy,len,ret,x,y:Integer;
  134. rc: TRect;
  135. szText:PChar;
  136. begin
  137.    if csDesigning in ComponentState then
  138.      exit;
  139.    SetCapture(Handle);
  140.    cy:=GetSystemMetrics(SM_CYSCREEN);
  141.    cx:=GetSystemMetrics(SM_CXSCREEN);
  142.    {sText.Add('XPos: '+IntToStr(XPos));
  143.    sText.Add('YPos: '+IntToStr(YPos));}
  144.    szText:=sText.GetText;
  145.    Canvas.Font:=Font;
  146.    Canvas.Pen.Width:=2;
  147.    ret:=DrawText(Canvas.Handle,szText,-1,rc,DT_LEFT or DT_CALCRECT);
  148.    if XPos=0 then
  149.      x:= (cx-(rc.right-rc.left)) div 2
  150.    else
  151.      x:=XPos;
  152.    if YPos=0 then
  153.      y:= (cy-(rc.bottom-rc.top)) div 2
  154.    else
  155.      y:=YPos;
  156.    SetBounds(x,y,rc.right-rc.left+40,
  157.                 rc.bottom-rc.top+30);
  158.    if timerClose > 0 then
  159.    begin
  160.       Timer1.Interval:=timerClose;
  161.       Timer1.Enabled:=true;
  162.    end;
  163. end;
  164.  
  165. procedure TRopInst.FormCreate(Sender: TObject);
  166. begin
  167.    sText:=TStringList.Create;
  168.    formBrush:=TBrush.Create;
  169.    XPos:=0;
  170.    YPos:=0;
  171.    timerClose:=0;
  172. end;
  173.  
  174. procedure TRopInst.FormClose(Sender: TObject; var Action: TCloseAction);
  175. begin
  176.    sText.Free;
  177.    formBrush.Free;
  178.    ReleaseCapture;
  179. end;
  180.  
  181. procedure TRopInst.FormMouseDown(Sender: TObject; Button: TMouseButton;
  182.   Shift: TShiftState; X, Y: Integer);
  183. begin
  184.     Close;
  185. end;
  186.  
  187. procedure TRopInst.Timer1Timer(Sender: TObject);
  188. begin
  189.     Close;
  190. end;
  191.  
  192. end.
  193.